package com.woniu.p2p.behindServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.p2p.behindService.CommentManagerService;
import com.woniu.p2p.entity.Invest;
import com.woniu.p2p.entity.InvestComment;
import com.woniu.p2p.mapper.InvestCommentMapper;
import com.woniu.p2p.mapper.InvestMapper;
import com.woniu.p2p.vo.InvestAndCommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CommentManagerServiceImpl implements CommentManagerService {

    @Autowired
    InvestCommentMapper investCommentMapper;
    @Autowired
    InvestMapper investMapper;


    @Override
    public PageInfo<InvestAndCommentVo> findAllInvestComment(Integer start, Integer num, String commentstatus, Date predate, Date nextdate, String commentkeyword) {
        PageHelper.startPage(start,num);
        List<InvestAndCommentVo> list = investCommentMapper.findAllInvestAndCommentVo(commentstatus, predate, nextdate, commentkeyword);
        PageInfo<InvestAndCommentVo> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<InvestAndCommentVo> findAllComments(int[] id) {
        return investCommentMapper.findAllCooments(id);
    }

    @Override
    public InvestComment findAllComment(int id) {
        return investCommentMapper.selectByPrimaryKey(id);
    }

    @Override
    public Invest findAllInvestById(int id) {
        return investMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Invest> findAllInvest() {
        return investMapper.selectAll();
    }

    @Override
    public int insertComment(InvestComment investComment) {
        return investCommentMapper.insert(investComment);
    }

    @Override
    public int deleteCommentById(int id) {
        return investCommentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<InvestComment> selectallcomment() {
        return investCommentMapper.selectAll();
    }
}
